package com.hou.msmservice.service;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * @author shkstart
 * @create 2021-11-18-21:36
 */
@Service
public class MsmServiceImpl implements MsmService{

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Override
    public boolean send(String sixBitRandom, String phone) {

        // 将随机数放入redis作为验证码,并设置过期时间
        redisTemplate.opsForValue().set(phone,sixBitRandom,5, TimeUnit.MINUTES);

        String code = redisTemplate.opsForValue().get(phone);

        if (!StringUtils.isEmpty(code)) {
            return true;
        }

        return false;
    }
}
